<!-- 口岸现场查验-智能查验-货物人工查验掏箱作业 -->
<template>
  <div>
    <!--引用表格-->
    <BasicTable @register="registerTable" :rowSelection="rowSelection" :showIndexColumn="true">
      <!--插槽:table标题-->
      <template #tableTitle>
        <!-- <a-button type="primary" preIcon="ant-design:plus-outlined" @click="handleCreate">新增</a-button> -->
        <JThirdAppButton biz-type="user" :selected-row-keys="selectedRowKeys" syncToApp syncToLocal />
        <a-dropdown v-if="selectedRowKeys.length > 0">
          <template #overlay>
            <a-menu>
              <a-menu-item key="1" @click="batchHandleDelete">
                <Icon icon="ant-design:delete-outlined" />
                删除
              </a-menu-item>
            </a-menu>
          </template>
          <a-button
            >批量操作
            <Icon icon="mdi:chevron-down" />
          </a-button>
        </a-dropdown>
      </template>
      <!-- 点击（非）报关单号 -->
      <template #customsDeclaration="{ record }">
        <div class="link" @click="openDetailModal(record, 'declaration')">{{ record.beiyong }}</div>
      </template>
      <!-- 点击舱单号 -->
      <template #manifestNum="{ record }">
        <div class="link" @click="openDetailModal(record, 'manifest')">{{ record.beiyong }}</div>
      </template>
      <!-- 点击查验记录单号 -->
      <template #recordNum="{ record }">
        <div class="link" @click="openDetailModal(record, 'record')">{{ record.beiyong }}</div>
      </template>
      <!--操作栏-->
      <template #action="{ record }">
        <TableAction :actions="getTableAction(record)" />
      </template>
    </BasicTable>
    <!--表单抽屉-->
    <detailModal @register="registerModal" />
  </div>
</template>

<script lang="ts" name="system-user" setup>
  //ts语法
  import { unref } from 'vue';
  import JThirdAppButton from '/@/components/jeecg/thirdApp/JThirdAppButton.vue';
  import { BasicTable, TableAction, ActionItem } from '/@/components/Table';
  import detailModal from './detailModal.vue';
  import { useModal } from '/@/components/Modal';
  import { useListPage } from '/@/hooks/system/useListPage';
  import { useMessage } from '/@/hooks/web/useMessage';
  import { columns, searchFormSchema } from './putIntoEffect.data';
  import { useMessageHref } from '/@/views/system/message/components/useSysMessage';
  import { listPutInfoEffect, deletePutInfoEffect, batchDeletePutInfoEffect } from './putIntoEffect.api';
  //注册drawer
  const { createMessage } = useMessage();
  const [registerModal, { openModal: openDetail }] = useModal();
  // const [registerDeclarationModal, { openModal: openDetail2 }] = useModal();
  const { goPage } = useMessageHref();
  // 列表页面公共参数、方法
  const { tableContext } = useListPage({
    designScope: 'user-list',
    tableProps: {
      title: '',
      api: listPutInfoEffect,
      // showActionColumn: false,
      columns: columns,
      size: 'small',
      formConfig: {
        // labelWidth: 200,
        schemas: searchFormSchema,
      },
      actionColumn: {
        width: 120,
      },
      beforeFetch: (params) => {
        return Object.assign({ column: 'createTime', order: 'desc' }, params);
      },
    },
  });

  //注册table数据
  const [registerTable, { reload }, { rowSelection, selectedRows, selectedRowKeys }] = tableContext;

  /**
   * 删除事件
   */
  async function handleDelete(record) {
    if ('admin' == record.username) {
      createMessage.warning('管理员账号不允许此操作！');
      return;
    }
    await deletePutInfoEffect({ id: record.id }, reload);
  }
  /**
   * 批量删除事件
   */
  async function batchHandleDelete() {
    let hasAdmin = unref(selectedRows).filter((item) => item.username == 'admin');
    if (unref(hasAdmin).length > 0) {
      createMessage.warning('管理员账号不允许此操作！');
      return;
    }
    await batchDeletePutInfoEffect({ ids: selectedRowKeys.value }, () => {
      selectedRowKeys.value = [];
      reload();
    });
  }
  /**
   * 操作栏
   */
  function getTableAction(record): ActionItem[] {
    return [
      {
        label: '删除',
        popConfirm: {
          title: '是否确认删除',
          confirm: handleDelete.bind(null, record),
        },
      },
    ];
  }
  /**
   * 打开详情
   */
  function openDetailModal(record, type) {
    // let anntId = record.anntId;
    // editCementSend({ anntId: anntId }).then((res) => {
    //   reload();
    //   syncNotic({ anntId: anntId });
    // });//获取数据
    const openModalFun = () => {
      openDetail(true, {
        record,
        type: type,
      });
    };
    goPage(record, openModalFun);
  }
</script>

<style scoped>
  .link {
    color: #1677ff;
  }
  .link:hover {
    text-decoration: underline;
    cursor: pointer;
  }
</style>
